package chp09.homework;

import java.util.Arrays;
import java.util.Scanner;

public class Home2 {


    static int[] nums = new int[5];

    //记录存放的值的数量
    static int count = 0;

    public static void addNum(int num){
        //承担把数字放入数组的功能
        System.out.println("承担把数字放入数组的功能:"+num);
        for (int i = 0; i < nums.length; i++) {
            //找空位进行存放
            if (nums[i] == 0){
                nums[i] = num;
                count++;
                break;
            }
        }
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while (true){
            System.out.print("请输入一个正整数:");
            int num = input.nextInt();
            if(num > 0) {
                addNum(num);
            }else{
                System.out.println("输入的不是正整数，录入失败");
            }

            if(count == nums.length){
                System.out.println("数组存放满了，退出输入");
                break;
            }
        }
        System.out.println("------------------");
        System.out.println(Arrays.toString(nums));
    }
}
